"use strict";
import list2019 from "./2019";
import list2018 from "./2018";
import list2017 from "./2017";
import binglike from "./binglike";
import chuanranganran from "./chuanranganran";
import erbihouke from "./erbihouke";
import fangsheke from "./fangsheke";
import huxike from "./huxike";
import fengshike from "./fengshike";

const map = new Map();
map.set(2019, list2019);
map.set(2018, list2018);
map.set(2017, list2017);
map.set("病理科", new Map(binglike));
map.set("传染感染", new Map(chuanranganran));
map.set("耳鼻喉科", new Map(erbihouke));
map.set("放射科", new Map(fangsheke));
map.set("呼吸科", new Map(huxike));
map.set("风湿病", new Map(fengshike));

class YY {
    private map: any = map;
    private all: any = new Set();
    allName: any[] = [];
    constructor() {
        this.allName = this.getAllName(this.map);
    }
    private getAllName(map = this.map): any {
        for (let key of map.keys()) {
            let value = map.get(key);
            if (Object.prototype.toString.call(value) === "[object Array]") {
                for (let i = 0, len = value.length; i < len; i++) {
                    value[i]["zh_rank"] = this.number2Chinese(value[i]["排名"]);
                    this.all.add(value[i]["医院名称"]);
                }
            } else if (
                Object.prototype.toString.call(value) === "[object Map]"
            ) {
                this.getAllName(value);
            }
        }
        return [...this.all];
    }
    getListByName(
        name: string,
        parent: string = "医院综合",
        map = this.map,
        arr: any[] = []
    ): any {
        for (let key of map.keys()) {
            let value = map.get(key);
            if (Object.prototype.toString.call(value) === "[object Array]") {
                for (let i = 0, len = value.length; i < len; i++) {
                    if (value[i]["医院名称"] === name) {
                        arr.push([key, parent, value[i]]);
                    }
                }
            } else if (
                Object.prototype.toString.call(value) === "[object Map]"
            ) {
                this.getListByName(name, key, value, arr);
            }
        }
        return arr;
    }
    getListByKey(key: any) {
        return [...this.map.get(key)];
    }
    number2Chinese(num: number) {
        let chinese = [
            "零",
            "一",
            "二",
            "三",
            "四",
            "五",
            "六",
            "七",
            "八",
            "九",
        ];
        let unit = ["千", "百", "十", ""];
        let numStr = num.toString();
        let str = "";
        unit = unit.slice(unit.length - numStr.length);
        for (let i = 0, len = numStr.length; i < len; i++) {
            let index = parseInt(numStr.charAt(i), 10);
            str += chinese[index] + unit[i];
        }
        str = str
            .replace(/零(千|百|十)/gi, "零")
            .replace(/(零)+/gi, "")
            .replace(/一十/gi, "十");
        return str;
    }
}

let yy = new YY();
// console.log(yy.allName);
// console.log(yy.getAllName());
// console.log(yy.getListByName("四川大学华西医院2"));
// console.log(yy.getListByName("中国医学科学院北京协和医院"));
// console.log(yy.getListByName("中国医学科学院北京协和医院"));
// console.log(yy.getListByKey("病理科"));

// console.log(yy.getAllName());

export default yy;
